# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=MyST-Parser
pkgbase=mingw-w64-python-${_realname,,}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname,,}")
pkgver=0.18.1
pkgrel=1
pkgdesc="An extended commonmark compliant parser, with bridges to docutils/sphinx (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/executablebooks/MyST-Parser'
license=('MIT')
options=('!strip')
depends=("${MINGW_PACKAGE_PREFIX}-python-docutils"
         "${MINGW_PACKAGE_PREFIX}-python-jinja"
         "${MINGW_PACKAGE_PREFIX}-python-markdown-it-py"
         "${MINGW_PACKAGE_PREFIX}-python-mdit_py_plugins"
         "${MINGW_PACKAGE_PREFIX}-python-typing_extensions"
         "${MINGW_PACKAGE_PREFIX}-python-sphinx"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-flit-core")
source=("${_realname}-${pkgver}.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('8da06c60167b792d0235aee5f1efd1b9ecdd010daa57409603a5b62e9b09315d')

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  msg "Python install for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname,,}/LICENSE"
}
